/**
 * @file serial.h
 * @brief serial 
 * @author JakeYang <add358@gmail.com>
 * @version 0.1
 * @date 2016-03-10
 */

#ifndef __SERIAL_H__
#define __SERIAL_H__

#include <termios.h>

typedef struct _Serial Serial;

typedef enum  {
	NO_FLOW_CONTROL,
    HARDWARD_CONTROL,
    SOFTWARD_CONTROL
}FlowControl;

typedef enum {
	NONE_PARITY,
	EVENT_PARITY,
	ODD_PARITY,
	MARK_PARITY,
	SPACE_PARITY
}Parity;

typedef enum {
    BAUD_9600  = B9600,
    BAUD_19200 = B19200,
    BAUD_115200 = B115200,
}BaudRate;

typedef enum {
    DATA_5 = CS5,
    DATA_6 = CS6,
    DATA_7 = CS7,
    DATA_8 = CS8
} DataBits;

typedef enum {
    ONE_STOP,
    TWO_STOP
} StopBits;

typedef enum {
    SKIP_POLICY,
    PASS_ZERO_POLICY,
    IGNORE_POLICY,
    STOP_RECEIVING_POLICY,
}DATA_ERROR_POLICY;

Serial *serial_open(const char *name);
void serial_close(Serial *s);

int serial_set_speed(Serial *s, BaudRate baudRate);
int serial_set_flow_control(Serial *s, FlowControl flowControl);
int serial_set_parity(Serial *s, Parity parity);
int serial_set_databits(Serial *s, DataBits bits);
int serial_set_stopbits(Serial *s, StopBits bits);

int serial_read(Serial *s, char *buf, int len);
int serial_write(Serial *s, const char *buf, int len);

#endif /* end of include guard */
